home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / Libraries / Aidan's Class Libraries / Source / Action / ActionHandler.cpp next >
Encoding:
Text File  |  1997-05-31  |  2.0 KB  |  80 lines  |  [TEXT/CWIE]

  1. //Copyright (c) 1997 Aidan Cully
  2. //All rights reserved
  3.  
  4. #include <Menus.h>
  5. #include <Devices.h>
  6. #include "CLActionHandler.h"
  7.  
  8. MActionHandler *MActionHandler::sCurHandler = 0l;
  9.  
  10. MActionHandler::MActionHandler( MActionHandler *super )
  11. {
  12.     mSuperHandler = super;
  13.     mActive = false;
  14. }
  15.  
  16. Boolean MActionHandler::SetSuperHandler( MActionHandler *super )
  17. {
  18.     mSuperHandler = super;
  19.     return( true );
  20. }
  21.  
  22. //MActionHandler::MakeActive()
  23. //    uses:
  24. //        This procedure deactivates the current Handler tree, then activates its own (from
  25. //        itself up to the superest handler of all).  All actions will now be sent to the root
  26. //        of this procedure.
  27. //    return values:
  28. //        0: success
  29. //        other values can be returned by the subclassed version, and only the programmer at that
  30. //        stage would have any idea what they mean.
  31. SInt8 MActionHandler::MakeActive()
  32. {
  33.     if( sCurHandler == this )
  34.         return( 0 );
  35.     if( sCurHandler ) {
  36.         sCurHandler->MakeInactive();
  37.         //set the curHandler == 0, so that this handler's superhandlers (if any) will not call
  38.         //MakeInactive() again.
  39.         sCurHandler = 0l;
  40.     }
  41.     if( mSuperHandler )
  42.         mSuperHandler->MakeActive();
  43.     //Now, we can finally set the curHandler;
  44.     sCurHandler = this;
  45.     mActive = true;
  46.     return( 0 );
  47. }
  48.  
  49. //This procedure should only be called from MakeActive();
  50. SInt8 MActionHandler::MakeInactive()
  51. {
  52.     if( mSuperHandler )
  53.         mSuperHandler->MakeInactive();
  54.     mActive = false;
  55.     return( 0 );
  56. }
  57.  
  58. //MActionHandler::HandleAction()
  59. //    in:
  60. //        UInt32 action:
  61. //            this number corresponds to the number returned by MenuSelect() or MenuKey(), or
  62. //            any application defined values.  It is up to the programmer to make sure that the
  63. //            two don't conflict.
  64. SInt8 MActionHandler::HandleAction( UInt32 action )
  65. {
  66.     if( mSuperHandler )
  67.         return( mSuperHandler->HandleAction( action ) );
  68.     return( 0 );
  69. }
  70.  
  71. void MActionHandler::OpenDeskAcc( UInt32 action )
  72. {
  73.     int mID, mItem;
  74.     Str255 theName;
  75.  
  76.     mID = action>>16;
  77.     mItem = (action&0x0000ffff);
  78.     GetMenuItemText( GetMenuHandle( mID ), mItem, theName );
  79.     ::OpenDeskAcc( theName );
  80. }